package com.aiju.cash.ui.multiple_shops.activity;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.aiju.base.activity.BaseTitleActivity;
import com.aiju.cash.R;
import com.aiju.cash.ui.enter.CheckInActivity;
import com.aiju.cash.ui.multiple_shops.widget.MenuLinearLayout;
import com.aiju.utils.T;

/**
 * @author: 佐为
 * @date: 2017-06-12 15:40
 * @version: V1.0
 * @Description: 新增普通门店
 */
public class ShopAddActivity extends BaseTitleActivity {

    private String shopType;
    private TextView directTextView, joinTextView;

    private String title;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_shop);
        title = getIntent().getStringExtra("title");
        setCenterTitle(title);
        directTextView = (TextView) findViewById(R.id.tv_shop_direct);
        joinTextView = (TextView) findViewById(R.id.tv_shop_join);
        Drawable drawable = getResources().getDrawable(R.drawable.selector_shop_direct);
        // 这一步必须要做,否则不会显示.
        drawable.setBounds(0, 0, MenuLinearLayout.dip2px(this, 155), MenuLinearLayout.dip2px(this, 155));
        directTextView.setCompoundDrawables(null, drawable, null, null);
        Drawable drawable1 = getResources().getDrawable(R.drawable.selector_shop_direct);
        // 这一步必须要做,否则不会显示.
        drawable1.setBounds(0, 0, MenuLinearLayout.dip2px(this, 155), MenuLinearLayout.dip2px(this, 155));
        joinTextView.setCompoundDrawables(null, drawable1, null, null);

        directTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                directTextView.setSelected(true);
                joinTextView.setSelected(false);
                shopType = "直营店";
            }
        });
        joinTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                joinTextView.setSelected(true);
                directTextView.setSelected(false);
                shopType = "加盟店";
            }
        });

        findViewById(R.id.btn_shop_next).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (TextUtils.isEmpty(shopType)) {
                    T.ToastShort("请选择您创建的门店类型");
                    return;
                }
                if (title.equals("新增普通门店")) {
                    Intent intent = new Intent(ShopAddActivity.this, ShopAddOrInfoActivity.class);
                    intent.putExtra("shopType", shopType);
                    intent.putExtra("showType", ShopAddOrInfoActivity.SHOW_ADD);
                    startActivity(intent);
                    finish();
                } else {
                    Intent intent = new Intent(ShopAddActivity.this, CheckInActivity.class);
                    intent.putExtra("save", 1);
                    intent.putExtra("shopType", shopType);
                    startActivity(intent);
                    finish();
                }

            }
        });
    }
}
